<template>
  <div class="gl_contentBox gl_heightFull">
    <div class="demo-input-suffix gl_searchBox">
      <el-row :gutter="20">
        <el-col :md="6" :lg="4">
          <p>姓名</p>
          <el-input v-model="qo.StudentName" placeholder="请输入学员姓名" clearable size="mini" @change="getPageList()" />
        </el-col>
        <el-col :md="6" :lg="4">
          <p>证件号码</p>
          <el-input v-model="qo.IdCardNumber" placeholder="请输入证件号码" clearable size="mini" @change="getPageList()" />
        </el-col>
        <el-col :md="6" :lg="4">
          <p>性别</p>
          <el-select v-model="qo.GenderCode" size="mini" placeholder="请选择性别" @change="getPageList()">
            <el-option label="全部" :value="null" />
            <el-option label="男" value="M" />
            <el-option label="女" value="W" />
          </el-select>
        </el-col>
        <el-col :md="6" :lg="4">
          <p>班级</p>
          <el-select v-model="qo.ClassName" size="mini" placeholder="请选择班级" @change="getPageList()">
            <el-option label="全部" :value="null" />
            <el-option v-for="item in classList" :key="item.id" :label="item.name" :value="item.name" />
          </el-select>
        </el-col>
        <el-col :md="6" :lg="4">
          <p>教练</p>
          <el-input v-model="qo.CoachName" placeholder="请输入教练" clearable size="mini" @change="getPageList()" />
        </el-col>
        <el-col :md="6" :lg="4" class="search_btn">
          <!-- 查询按钮 -->
          <el-button type="primary" size="mini" @click="getPageList()">筛选</el-button>
          <!-- 重置按钮 -->
          <el-button type="warning" size="mini" @click="clickReset()">{{ $t('button.Reset') }}</el-button>
        </el-col>
      </el-row>
    </div>
    <el-table v-loading="tableLoading" :data="tableData" class="gl_table_noBorder gl_mt_15" size="mini" style="width: 100%;">
      <el-table-column label="序号" type="index" width="46" />
      <el-table-column label="姓名" align="center" width="70">
        <template slot-scope="{row}">
          <!--<PersonalImage :imgurl="row.imagePath" imgheight="60px" />-->
          <div v-if="!row.face" class="face_noimg" />
          <img v-else :src="row.face.faceUrl" class="face_img">
        </template>
      </el-table-column>
      <el-table-column prop="name" :min-width="80" />
      <el-table-column label="证件号" prop="idCardNumber" :min-width="150" />
      <el-table-column label="性别" prop="gender.name" :min-width="60" />
      <el-table-column label="所在班级" :min-width="200">
        <template slot-scope="{row}">
          <div v-for="(classs,index) in row.classStudents" :key="index">
            {{ classs.class.name }}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="教练" :min-width="100">
        <template slot-scope="{row}">
          <div v-for="coach in row.studentCoachs" :key="coach.id">
            {{ coach.employee && coach.employee.name }}
          </div>
        </template>
      </el-table-column>
      <el-table-column :label="$t('table.actions')" width="120">
        <template slot-scope="{ row }">
          <el-button size="mini" type="text" @click="clickCollection(row)">采集</el-button>
          <el-button size="mini" type="text" @click="clickEdit(row.id)">编辑</el-button>
          <el-button size="mini" type="text" style="color:#FF3434" @click="clickEmpty(row)">清空</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-row class="gl_pt_15" style="text-align: right;">
      <el-pagination
        :current-page="qo.Page"
        :page-size="qo.MaxResultCount"
        :total="total"
        layout="total,sizes,prev,pager,next,jumper"
        :page-sizes="[10, 20, 30, 40]"
        @size-change="sizeChange"
        @current-change="pageIndexChange"
      />
    </el-row>

    <faceCollection ref="faceCollection" @refresh="getPageList" />
  </div>
</template>

<script>
import faceCollection from './faceCollection.vue';
// import PersonalImage from '@/components/PersonalImage/index';
import { api_GET_ClubStudent, api_DELETE_ClubFace, api_GET_ClubClass } from '@/extend/api/hallswaggerApi/app.js';
import { Api_GET_ClubStudentQO, UpdateFaceInput, Api_DELETE_ClubFaceQO } from '@/lib/form/hall/swaggerForm';
export default {
  components: {
    faceCollection
  },
  data() {
    return {
      qo: new Api_GET_ClubStudentQO(),
      collectQO: new UpdateFaceInput(),
      deleteQO: new Api_DELETE_ClubFaceQO(),
      tableLoading: false,
      tableData: [],
      total: 1,
      classList: [],
      thisCancas: null,
      thisContext: null,
      thisVideo: null,
      imgSrc: '' // 图片拍照
    };
  },
  created() {
    this.getClass();
    this.getPageList();
  },
  methods: {
    getPageList(page) {
      this.qo.IncludeStudentCoachs = true;
      this.qo.IncludeClassStudents = true;
      this.qo.IncludeGender = true;
      this.qo.IncludeFace = true;
      this.qo.IncludeStudentMembershipCards = true;
      this.qo.Page = page || 1;
      this.qo.SkipCount = (this.qo.Page - 1) * this.qo.MaxResultCount;
      this.qo.IsEnable = null;
      this.qo.Sorting = 'creationTime DESC';
      this.tableLoading = true;
      api_GET_ClubStudent(this.qo).then((res) => {
        this.tableLoading = false;
        this.total = res.totalCount;
        this.tableData = res.items;
      }, error => {
        const _msg = error.error.message || error.message;
        this.$message({ type: 'error', message: _msg });
      });
    },
    // 获取班级列表
    getClass() {
      var that = this;
      api_GET_ClubClass({ HasScheduledCourse: null, IncludeCourse: true, IncludeClassStudent: false }).then(res => {
        that.classList = res.items || [];
      }).catch(error => {
        that.$message({ type: 'error', message: error.error.message || '获取班级列表失败' });
      });
    },
    clickCollection(item) {
      this.$refs.faceCollection.dialogVisible = true;
      this.$refs.faceCollection.collect();
      this.$refs.faceCollection.info = { 'name': item.name, 'idCardNumber': item.idCardNumber };
      this.$refs.faceCollection.collectQO.studentId = item.id;
    },
    clickEdit(id) {
      this.$router.push({
        name: 'FaceDetail',
        query: {
          id: id
        }
      });
    },
    clickEmpty(item) {
      const that = this;
      this.deleteQO.studentId = item.id;
      that.$confirm(`您确定要删除${item.name}的面部信息吗？`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.loading = true;
          api_DELETE_ClubFace(that.deleteQO).then((res) => {
            that.$message({ type: 'success', message: '删除成功' });
            that.getPageList(that.qo.Page);
          }, error => {
            const _msg = error.error.message || error.message;
            that.$message({ type: 'error', message: _msg });
          });
        })
        .catch(() => {
        });
    },
    clickReset() {
      this.qo = new Api_GET_ClubStudentQO();
      this.getPageList();
    },
    // 分页
    sizeChange(MaxResultCount) {
      this.qo.MaxResultCount = MaxResultCount;
      this.getPageList();
    },
    pageIndexChange(currentPage) {
      this.getPageList(currentPage);
    }
  }
};
</script>

<style lang="scss" scoped>
.face_img {
  width: 60px;
  height: 60px;
  vertical-align: middle;
  border-radius: 6px;
  border: 1px solid #F0F0F0;
}
.face_noimg {
  width: 60px;
  height: 60px;
}
</style>
